package net.anzhuo.controller.db.report;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.utils.RedisUtil;
import net.anzhuo.entity.GsBase;
import net.anzhuo.entity.GsCompanyTaxCredit;
import net.anzhuo.entity.db.TaxAccountResponseResult;
import net.anzhuo.entity.db.TaxAccountResult;
import net.anzhuo.entity.db.TaxResponseResult;
import net.anzhuo.entity.db.TaxResult;
import net.anzhuo.service.GsBaseService;
import net.anzhuo.service.GsCompanyTaxCreditService;
/**
 * 
 * @author jiyk
 * @税务登记号查询
 */
@RestController
@Slf4j
public class ShuiWuController {

	@Autowired
	private GsCompanyTaxCreditService gsCompanyTaxCreditService;
	@Autowired
	private GsBaseService gsBaseService;
	
	@RequestMapping("/ECICreditCode/GetCreditCode")
	public TaxResponseResult GetCreditCode(String keyWord) {
		log.info("===>ShuiWu_searchKey="+keyWord+"");
		long startTime=System.currentTimeMillis();
		TaxResponseResult rr = null;
		try {
			rr = (TaxResponseResult)RedisUtil.get("shuiwu:GetCreditCode:"+keyWord);
			if (rr != null) {
				 long endTime=System.currentTimeMillis();
				 float excTime=(float)(endTime-startTime)/1000;
				 log.info(" shuiwu:GetCreditCode 执行时间："+excTime+"s");
				return rr;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		GsCompanyTaxCredit taxQuery = new GsCompanyTaxCredit();
		GsBase base = gsBaseService.getByName(keyWord);
		taxQuery.setCoMd5(base.getMd5());
		List<GsCompanyTaxCredit> retList = gsCompanyTaxCreditService.getBycoMd5(base.getMd5());
		
		TaxResponseResult responseResult = new TaxResponseResult();
		responseResult.setStatus("200");
		responseResult.setMessage("查询成功");
		
		TaxResult trr=new TaxResult();
		
		if(retList.size()>0)
		{
			trr.setStatus(base.getName());
			trr.setCreditCode(base.getCreditCode());
			trr.setEconKind(base.getEnterpriseType());
			trr.setStatus(base.getEnterpriseStatus());
			trr.setTel(base.getTel());
			trr.setAddress(base.getRegAddress());
		}else
		{
			responseResult.setStatus("201");
			responseResult.setMessage("查询无结果");
		}
		
		if(keyWord==null||keyWord.equals(""))
		{
			responseResult.setStatus("204");
			responseResult.setMessage("查询无结果");
		}
		responseResult.setResult(trr);		
		try {
			RedisUtil.set("shuiwu:GetCreditCode:"+keyWord, responseResult);
		} catch (Exception e) {
			e.printStackTrace();
		}
		 long endTime=System.currentTimeMillis();
		 float excTime=(float)(endTime-startTime)/1000;
		 log.info(" shuiwu:GetCreditCode 执行时间："+excTime+"s");
		return responseResult;
	}
	
	
	
	@RequestMapping("/ECICreditCode/GetCreditCodeNew")
	public TaxAccountResponseResult GetCreditCodeNew(String keyWord) {
		log.info("===>ShuiWu_searchKey="+keyWord+"");
		
		TaxAccountResponseResult rr = null;
		try {
			rr = (TaxAccountResponseResult)RedisUtil.get("shuiwu:GetCreditCodeNew:"+keyWord);
			if (rr != null) {
				return rr;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		GsCompanyTaxCredit taxQuery = new GsCompanyTaxCredit();
		GsBase base = gsBaseService.getByName(keyWord);
		taxQuery.setCoMd5(base.getMd5());
		List<GsCompanyTaxCredit> retList = gsCompanyTaxCreditService.getBycoMd5(base.getMd5());
		
		TaxAccountResponseResult responseResult = new TaxAccountResponseResult();
		responseResult.setStatus("200");
		responseResult.setMessage("查询成功");
		
		TaxAccountResult trr=new TaxAccountResult();
		
		if(retList.size()>0)
		{
			trr.setStatus(base.getName());
			trr.setCreditCode(base.getCreditCode());
			trr.setEconKind(base.getEnterpriseType());
			trr.setStatus(base.getEnterpriseStatus());
			trr.setTel(base.getTel());
			trr.setAddress(base.getRegAddress());
			trr.setBank("");
			trr.setBankAccount("");
		}else
		{
			responseResult.setStatus("201");
			responseResult.setMessage("查询无结果");
		}
		
		if(keyWord==null||keyWord.equals(""))
		{
			responseResult.setStatus("204");
			responseResult.setMessage("查询无结果");
		}
		responseResult.setResult(trr);		
		try {
			RedisUtil.set("shuiwu:GetCreditCodeNew:"+keyWord, responseResult);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return responseResult;
	}
	
	
	
}
